<template>
  <div class="hnapay-config gray-box top-redius border-bottom-gray">
    <div class="title">{{$t('sysManagement.hnapayPaymentConfiguration')}}</div>
    <el-form
      ref="dataForm"
      label-width="180px"
      size="mini"
      class="set-form"
      label-position="left"
      @keyup.enter.native="dataFormSubmit()"
      :rules="dataRule"
      :model="dataForm"
    >
      <el-form-item :label="$t('sysManagement.merId')" style="width:640px" prop="merId">
        <el-input v-model="dataForm.merId" :placeholder="$t('sysManagement.merId')" controls-position="right"></el-input>
      </el-form-item>
      <el-form-item :label="$t('sysManagement.signAlgorithm')" style="width:640px" prop="signAlgorithm">
        <el-input v-model="dataForm.signAlgorithm" :placeholder="$t('sysManagement.signAlgorithm')" controls-position="right"></el-input>
      </el-form-item>
      <el-form-item :label="$t('sysManagement.algorithm')" style="width:640px" prop="algorithm">
        <el-input v-model="dataForm.algorithm" :placeholder="$t('sysManagement.algorithm')" controls-position="unipayKey"></el-input>
      </el-form-item>
      <el-form-item :label="$t('sysManagement.ncountPublicKey')" style="width:640px" prop="ncountPublicKey">
        <el-input v-model="dataForm.ncountPublicKey" :placeholder="$t('sysManagement.ncountPublicKey')" controls-position="right"></el-input>
      </el-form-item>
      <el-form-item :label="$t('sysManagement.merPrivateKey')" style="width:640px" prop="merPrivateKey">
        <el-input v-model="dataForm.merPrivateKey" :placeholder="$t('sysManagement.merPrivateKey')" controls-position="right"></el-input>
      </el-form-item>
      <el-form-item :label="$t('sysManagement.merchantKjId')" style="width:640px" prop="merchantKjId">
        <el-input v-model="dataForm.merchantKjId" :placeholder="$t('sysManagement.merchantKjId')" controls-position="right"></el-input>
      </el-form-item>
      <el-form-item :label="$t('sysManagement.merchantAliId')" style="width:640px" prop="merchantAliId">
        <el-input v-model="dataForm.merchantAliId" :placeholder="$t('sysManagement.merchantAliId')" controls-position="right"></el-input>
      </el-form-item>
      <el-form-item :label="$t('sysManagement.merchantYsfId')" style="width:640px" prop="merchantYsfId">
        <el-input v-model="dataForm.merchantYsfId" :placeholder="$t('sysManagement.merchantYsfId')" controls-position="right"></el-input>
      </el-form-item>
      <el-form-item :label="$t('sysManagement.aliAppId')" style="width:640px" prop="aliAppId">
        <el-input v-model="dataForm.aliAppId" :placeholder="$t('sysManagement.aliAppId')" controls-position="right"></el-input>
      </el-form-item>
      <el-form-item :label="$t('sysManagement.wxAppId')" style="width:640px" prop="wxAppId">
        <el-input v-model="dataForm.wxAppId" :placeholder="$t('sysManagement.wxAppId')" controls-position="right"></el-input>
      </el-form-item>
      <el-form-item :label="$t('sysManagement.merchantJspId')" style="width:640px" prop="merchantJspId">
        <el-input v-model="dataForm.merchantJspId" :placeholder="$t('sysManagement.merchantJspId')" controls-position="right"></el-input>
      </el-form-item>
      <div class="default-btn" @click="dataFormSubmit()">{{$t('sysManagement.save')}}</div>
    </el-form>
    <span slot="footer" class="dialog-footer">
    </span>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dataForm: {
        merId: null,
        signAlgorithm: null,
        algorithm: null,
        ncountPublicKey: null,
        merPrivateKey: null,
        merchantKjId: null,
        merchantAliId: null,
        merchantYsfId: null,
        aliAppId: null,
        wxAppId: null,
        merchantJspId: null
      },
      dataRule: {
        machId: [
          { required: true, message: this.$i18n.t('sysManagement.hnapayMachIdNullTips'), trigger: 'blur' }
        ],
        signAlgorithm: [
          { required: true, message: this.$i18n.t('sysManagement.signAlgorithmNullTips'), trigger: 'blur' }
        ],
        algorithm: [
          { required: true, message: this.$i18n.t('sysManagement.algorithmNullTips'), trigger: 'blur' }
        ],
        ncountPublicKey: [
          { required: true, message: this.$i18n.t('sysManagement.ncountPublicKeyNullTips'), trigger: 'blur' }
        ],
        merPrivateKey: [
          { required: true, message: this.$i18n.t('sysManagement.merPrivateKeyNullTips'), trigger: 'blur' }
        ]
      }
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    init () {
      this.$nextTick(() => {
        this.$http({
          url: this.$http.adornUrl('/sys/pconfig/info/' + 'HNAPAY_CONFIG'),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({ data }) => {
          if (data) {
            this.dataForm = JSON.parse(data)
          }
        })
        this.$refs['dataForm'].resetFields()
      })
    },
    // 表单提交
    dataFormSubmit () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/sys/pconfig/save'),
            method: 'post',
            data: this.$http.adornData({
              'paramKey': 'HNAPAY_CONFIG',
              'paramValue': JSON.stringify(this.dataForm),
              'remark': this.$i18n.t('sysManagement.hnapayPaymentConfiguration')
            })
          }).then(({ data }) => {
            this.$message({
              message: this.$i18n.t('publics.operation'),
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          })
        }
      })
    }
  }
}
</script>
